﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Bass.Tools;
using MySql.Data.MySqlClient;

public partial class notice_board : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            dsdatabind();
        }
    }
    protected void dsdatabind()//绑定GridView1数据
    {
        //取到连接字符串
        string propertiesPath = Server.MapPath("mysqldb.properties");
        mytools mt = new mytools();
        string ConnString = mt.getMysqlConn(propertiesPath);

        //打开连接
        MySqlConnection myConnection = new MySqlConnection(ConnString);
        myConnection.Open();

        string newque = "SELECT * FROM notice_info order by addtime desc";
        MySqlDataAdapter datap = new MySqlDataAdapter(newque, myConnection);
        datap.Fill(dset);
        GridView1.DataSource = dset;
        this.GridView1.DataKeyNames = new string[] { "noticeid" };
        GridView1.DataBind();
        myConnection.Close();
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        this.dsdatabind();
    }

    //protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    //{
    //    if (e.Row.RowType == DataControlRowType.DataRow)
    //    {
    //        ((LinkButton)(e.Row.Cells[4].Controls[0])).Attributes.Add("onclick", "return confirm('确定删除吗？')");
    //    }
    //}


//    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
//    {
//        OleDbConnection Conn = new OleDbConnection();
//        Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("yang.mdb");
//        Conn.Open();
//        string id = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
//        OleDbCommand comm = new OleDbCommand("delete from 公告信息 where id=" + id, Conn);
//        comm.ExecuteNonQuery();
//        Conn.Close();
//        dsdatabind();
//    }
//    protected void Button11_Click(object sender, EventArgs e)
//    {
//        Response.Redirect("teacher_add_notice.aspx");
//    }
//    protected void Button12_Click(object sender, EventArgs e)
//    {
//        Response.Redirect("teacher_draft_list.aspx");
//    }
}